package com.example.world.servlet;

import com.example.world.dao.CountryDAO;
import com.example.world.domain.Country;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/countrylist")
public class AllCountryServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        CountryDAO dao = new CountryDAO();
        List<Country> list = new ArrayList<>();
        try {
             list =  dao.findAll();
            if(list!=null)
            {
                req.setAttribute("countrylist",list);
                req.getRequestDispatcher("allcountry.jsp").forward(req, resp);

            }
            else
            {
                resp.getWriter().print("find fail");
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }




    }
}
